import { ElNotification } from "element-plus";
import * as XLSX from "xlsx";

const ExportXlsx = (input) => {
  let fileName = "设备问题记录导出";
  // 创建工作表
  let data = XLSX.utils.json_to_sheet(input);
  // 创建工作簿
  let wb = XLSX.utils.book_new();
  //
  // 将工作表放入工作簿中
  XLSX.utils.book_append_sheet(wb, data, "设备问题记录导出");
  // 格式
  wb.Sheets["设备问题记录导出"]["!cols"] = [
    { wch: 7 },//number
    { wch: 12 },//equipment
    { wch: 17 },//eventTime
    { wch: 25 },//description
    { wch: 25 },//requirement
    { wch: 7 },//name
    { wch: 3 },//reported
    { wch: 3 },//replied
    { wch: 25 },//reply
    { wch: 3 },//status
    { wch: 17 },//createTime
    { wch: 17 },//uodateTime
  ];

  // 生成文件并下载
  XLSX.writeFile(wb, fileName + ".xlsx");
  console.log(wb);

  ElNotification({
    type: "success",
    title: `已导出${input.length}条记录`,
    message: `文件名：${fileName}.xlsx`,
  });
};

export default ExportXlsx;
